package com.chen.service.impl;

import com.chen.mapper.ExamPaperMapper;
import com.chen.mapper.StudentMapper;
import com.chen.mapper.SubjectMapper;
import com.chen.mapper.TeacherMapper;
import com.chen.service.AdminHomeService;
import com.chen.vo.HomeInfoDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 后台首页数据服务实现
 */
@Service
public class AdminHomeServiceImpl implements AdminHomeService {

    // 试卷
    @Autowired
    private ExamPaperMapper examPaperMapper;

    // 试题
    @Autowired
    private SubjectMapper subjectMapper;

    // 教师
    @Autowired
    private TeacherMapper teacherMapper;

    // 学生
    @Autowired
    private StudentMapper studentMapper;

    @Override
    public HomeInfoDTO getHomeInfo() {
        // 总试卷套数
        Long examPaperTotal = examPaperMapper.findAllCount();
        // 总题目数量
        Long subjectTotal = subjectMapper.findAllCount();
        // 教师人数
        Long teacherTotal = teacherMapper.findAllCount();
        // 总学生人数
        Long studentTotal = studentMapper.findAllCount();
        return HomeInfoDTO.builder()
                .examPaperTotal(examPaperTotal)
                .subjectTotal(subjectTotal)
                .teacherTotal(teacherTotal)
                .studentTotal(studentTotal).build();
    }
}
